package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketTopic;
import com.cskaoyan.market.db.domain.MarketTopicExample;
import com.cskaoyan.market.db.mapper.MarketTopicMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminTopicServiceImpl implements AdminTopicService {
    @Autowired
    MarketTopicMapper topicMapper;


    @Override
    public List<MarketTopic> getList(String page, String limit, String sort, String order, String title, String subtitle) {

        MarketTopicExample example = new MarketTopicExample();
        MarketTopicExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (StringUtils.isNotEmpty(title)) {
            criteria.andTitleLike("%" + title.trim() + "%");
        }
        if (StringUtils.isNotEmpty(subtitle)) {
            criteria.andSubtitleLike("%" + subtitle.trim() + "%");
        }
        example.setOrderByClause(sort + " " + order);
        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));

        return topicMapper.selectByExample(example);
    }


    @Override
    public void delete(MarketTopic marketTopic) {

        topicMapper.logicalDeleteByPrimaryKey(marketTopic.getId());

    }

    @Override
    public void batchDelete(List list) {
        for (Object o : list) {
            topicMapper.logicalDeleteByPrimaryKey((Integer) o);
        }
    }
}
